@using Extension
@using k8s.Models
@using BlazorApp.Pages.Common.Html
@if (LabelSelector != null && (LabelSelector.MatchLabels is { Count: > 0 } || LabelSelector.MatchExpressions is { Count: > 0 }))
{
    <HTableColumn Title="@Title" ExplainField="@ExplainField">
        @if (LabelSelector.MatchLabels is { Count: > 0 })
        {
            @foreach (var label in LabelSelector.MatchLabels)
            {
                    <ColorfulTag>@label.Key = @label.Value</ColorfulTag>
            }
        }
        @if (LabelSelector.MatchExpressions is { Count: > 0 })
        {
            @foreach (var expression in LabelSelector.MatchExpressions)
            {
                    @if (expression.Values is { Count: > 0 })
                    {
                       <ColorfulTag> @($"`{expression.Key}` {expression.OperatorProperty} [{string.Join(",", expression.Values)}]   ")</ColorfulTag>
                    }
                    else
                    {
                      <ColorfulTag>  @($"`{expression.Key}` {expression.OperatorProperty}  ")</ColorfulTag>
                    }
            }
        }

        @if (LabelSelector.ToJson() == "{}" && NullDesc != null)
        {
            <ColorfulTag>@NullDesc</ColorfulTag>
        }
    </HTableColumn>
}

@code {

    [Parameter]
    public V1LabelSelector LabelSelector { get; set; }

    [Parameter]
    public string ExplainField { get; set; }

    [Parameter]
    public string Title { get; set; }

    [Parameter]
    public string NullDesc { get; set; }

}
